extends Camera2D

var mousePos = Vector2.ZERO
func _ready():
	set_process_input(true)

func _input(event):
	# 捕获鼠标位置
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
		mousePos = get_global_mouse_position()

func _process(_delta):
    # 只要维持global_mouse_position不变，鼠标的位置相对于地图即为静止。
    # 当相机移动时,鼠标所在的位置会跟着移动
    # 鼠标位置先出现差值,再将插值通过移动相机补全,回归到同一位置
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		# 计算相机移动的距离
		var camera_movement = mousePos - get_global_mouse_position()
		# 更新相机位置
		position += camera_movement
